﻿using Kingdee.BOS.App.Data;
using Kingdee.BOS.Core;
using Kingdee.BOS.Core.DynamicForm.PlugIn;
using Kingdee.BOS.Core.DynamicForm.PlugIn.Args;
using Kingdee.BOS.Orm.DataEntity;
using Kingdee.BOS.Util;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;

namespace NS.MaterialChange
{
    [Description("当银行为工商时，修改文件名"), HotUpdate]
    public class RENAME : AbstractOperationServicePlugIn
    {
        public override void OnPreparePropertys(Kingdee.BOS.Core.DynamicForm.PlugIn.Args.PreparePropertysEventArgs e)
        {
            e.FieldKeys.Add("FID");
            e.FieldKeys.Add("FSRCBILLNO");
            e.FieldKeys.Add("FBILLNO");
            e.FieldKeys.Add("FBANKID");
            base.OnPreparePropertys(e);
        }

        public override void AfterExecuteOperationTransaction(AfterExecuteOperationTransaction e)
        {
            base.AfterExecuteOperationTransaction(e);
            string FID = "", FSRCBILLNO="", FBILLNO="", FBANKID="";
            foreach (DynamicObject item in e.DataEntitys)
            {
                if (item["ID"] != null && Convert.ToString(item["ID"]) != "")
                {
                    FID = Convert.ToString(item["ID"]);
                }
                if (item["FSRCBILLNO"] != null && Convert.ToString(item["FSRCBILLNO"]) != "")
                {
                    FSRCBILLNO = Convert.ToString(item["FSRCBILLNO"]);
                }
                if (item["BillNo"] != null && Convert.ToString(item["BillNo"]) != "")
                {
                    FBILLNO = Convert.ToString(item["BillNo"]);
                }
                if (item["FBANKID"] != null && Convert.ToString(item["FBANKID"]) != "")
                {
                    FBANKID = Convert.ToString(item["FBANKID"]);
                }
                string SQL = "/*dialect*/" + string.Format(@"update T_WB_ReceiptFile set fname='{1}' where FBILLNO='{0}'", FBILLNO, FSRCBILLNO+".pdf");
                DBUtils.ExecuteDynamicObject(this.Context, SQL);
            }
        }
    }
}
